package pri.damai.xiaowu.order.server.config;

import pri.damai.xiaowu.common.core.util.DateUtils;
import pri.damai.xiaowu.common.core.util.SnowflakeId;

import java.time.LocalDateTime;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

/**
 *
 * @Desc
 * @Author yxf
 * @Date 2022/4/29 19:01
 * 但行好事，莫问前程。
 */
public class IdUtil {

    public static final SnowflakeId snowId = new SnowflakeId(1, 13L);

    /**
     * 获取订单编号
     * @apiNote [附加描述]
     * @param orderType
     * @param merchantId
     * @return java.lang.String
     * @author DaMai
     * @date 2022/4/29 19:05
     */
    public static String getOrderNo(String orderType, String merchantId) {
        return orderType + merchantId + getDateTime() + randomNum(8);
    }

    private static String getDateTime() {
        return DateUtils.formatDateTime(LocalDateTime.now(),DateUtils.YYYYMMDDHHMMSS);
    }

    private static String randomNum(int places) {
        return ThreadLocalRandom.current().ints(0,9).limit(places).mapToObj(String::valueOf).collect(Collectors.joining());
    }

}
